package cn.edu.xmist.thread;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author zhongjinbin (jinbin.zhong@nascent.cn)
 * @version 1.0.0
 * @date 2020/11/27 13:17
 * @description com.fgood.thread
 */
public class ThreadShutdownHook implements Runnable {

    private final Set<Runnable> mqListenerThreads = Collections.synchronizedSet(new HashSet<Runnable>());
    private int i = 0;

    public ThreadShutdownHook() {
        Runtime.getRuntime().addShutdownHook(new Thread(this));
        System.out.println(">>> shutdown hook registered");
    }

    @Override
    public void run() {
        System.out.println("/n>>> About to execute: " + ThreadShutdownHook.class.getName() + ".run() to clean up before JVM exits.");
        this.stopMqListener();
        System.out.println(">>> Finished execution: " + ThreadShutdownHook.class.getName() + ".run()");
    }

    private void stopMqListener() {
        System.out.println("清除mq监听");
    }
}